package com.intellagric.service.iftmonitor.Impl.ift_equipment;

import com.github.pagehelper.PageHelper;
import com.intellagric.common.pojo.LayuiDataGridResult;
import com.intellagric.common.pojo.ResponseMessage;
import com.intellagric.dao.iftmonitor.EquipmentDao;
import com.intellagric.dao.iftmonitor.EquipmentStatusDao;
import com.intellagric.mapper.IftEquipmentStatusMapper;
import com.intellagric.module.iftmonitor.EquipmentStatusVo;
import com.intellagric.pojo.IftEquipmentStatus;
import com.intellagric.pojo.IftEquipmentStatusExample;
import com.intellagric.service.iftmonitor.ift_equipment.EquipmentStatusService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Author: zhy
 * @email: 1269679946@qq.com
 * @Date: 2018/10/20
 * @DESC： 设备状态信息服务实现
 */
@Service
public class EquipmentStatusServiceImpl implements EquipmentStatusService {

    @Autowired
    private IftEquipmentStatusMapper equipmentStatusMapper;

    @Autowired
    private EquipmentStatusDao equipmentStatusDao;

    /**
     * 添加设备状态信息
     * @param equipmentStatus
     * @return ResponseMessage
     */
    @Override
    public ResponseMessage addEquipmentStatus(IftEquipmentStatus equipmentStatus) {
        if (equipmentStatusMapper.insertSelective(equipmentStatus) == 1) {
            return ResponseMessage.success();
        } else {
            return ResponseMessage.fail();
        }
    }

    /**
     * 删除设备状态信息
     * @param id
     * @return ResponseMessage
     */
    @Override
    public ResponseMessage deleteEquipmentStatus(String id) {
        if (equipmentStatusMapper.deleteByPrimaryKey(id) == 1) {
            return ResponseMessage.success();
        } else {
            return ResponseMessage.fail();
        }
    }

    /**
     * 修改设备状态信息
     * @param equipmentStatus
     * @return ResponseMessage
     */
    @Override
    public ResponseMessage editEquipmentStatus(IftEquipmentStatus equipmentStatus) {
        if (equipmentStatusMapper.updateByPrimaryKeySelective(equipmentStatus) == 1) {
            return ResponseMessage.success();
        } else {
            return ResponseMessage.fail();
        }
    }

    /**
     * 查询设备状态详细信息
     * @param id
     * @return IftEquipmentStatus
     */
    @Override
    public IftEquipmentStatus getEquipmentStatusById(String id) {
        return equipmentStatusMapper.selectByPrimaryKey(id);
    }

    /**
     * 查询设备状态列表
     * @return LayuiDataGridResult
     */
    @Override
    public LayuiDataGridResult getEquipmentStatusList() {
        List<IftEquipmentStatus> equipmentStatusList = equipmentStatusDao.selectEquipmentStatusRelation();
        return LayuiDataGridResult.success().add(equipmentStatusList,equipmentStatusList.size());
    }

    /**
     * 多条件查询设备状态列表
     * @return LayuiDataGridResult
     */
    @Override
    public LayuiDataGridResult getEquipmentStatusListByVo(EquipmentStatusVo equipmentStatusVo) {
        List<IftEquipmentStatus> equipmentStatusList = equipmentStatusDao.selectEquipmentStatusListByVo(equipmentStatusVo);
        return LayuiDataGridResult.success().add(equipmentStatusList,equipmentStatusList.size());
    }

    /**
     * 分页查询设备状态列表
     * @param page
     * @param rows
     * @return LayuiDataGridResult
     */
    @Override
    public LayuiDataGridResult getEquipmentStatusPage(int page, int rows) {
        PageHelper.startPage(page,rows);
        IftEquipmentStatusExample equipmentStatusExample = new IftEquipmentStatusExample();
        equipmentStatusExample.createCriteria().andIdIsNotNull();
        List<IftEquipmentStatus> equipmentStatusList = equipmentStatusMapper.selectByExample(equipmentStatusExample);
        return LayuiDataGridResult.success().add(equipmentStatusList,this.getEquipmentStatusList().getCount());
    }
}
